import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

const store = new Vuex.Store({})

function registerStoreModule (module) {
  let moduleName = module.name
  if (!moduleName || store.hasModule(moduleName)) return
  const _module = Object.assign({}, module)
  store.registerModule(moduleName, _module)
}

const storeContexts = require.context('./modules', true, /index\.js$/)
storeContexts.keys().forEach(path => {
  registerStoreModule(storeContexts(path).default)
})


export default store
